package
{
	import mx.rpc.events.ResultEvent;
	
	import spark.formatters.DateTimeFormatter;

	public class WWOWeatherController
	{
		
		public var model:CurrentWeatherModel;
		
		public function WWOWeatherController()
		{
		}
		
		
		public function onResult(event:ResultEvent):void {
			var result:Object = JSON.parse(String(event.result)).data;
			var cnt:Object = result.current_condition[0];
			parseDatetime(cnt.observation_time, model.datetime);
			model.tempC = int(cnt.temp_C);
			 model.weather = cnt.weatherDesc[0].value;
			 model.weatherIcon = "";
			 model.windDirection = cnt.winddirDegree;
			 model.windMPS = Number(cnt.windspeedKmph)*0.277777778;
			 model.wind16Pt = cnt.winddir16Point;
			 model.humidity = Number(cnt.humidity);
			 model.pressure = Number(cnt.pressure);
			 model.cloudcover = Number(cnt.cloudcover);
			 model.visibility = Number(cnt.visibility);
			 model.precipMM = Number(cnt.precipMM);
		}
		
		private function parseDatetime(src:String, dst:Date):void {
			var hh:int = int(src.substr(0, 2));
			var mm:int = int(src.substr(3, 2));
			var ampm:String = src.substr(5, 2);
			if(ampm == "PM") hh += 12;
			dst.hoursUTC = hh;
			dst.minutesUTC = mm;
		}
	}
}